package com.example.q_kang.hhh.home;

import com.example.q_kang.hhh.api.JsonCallBack;
import com.hjq.toast.ToastUtils;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.base.BasePresenter;
import com.example.q_kang.hhh.home.SellGamActivity;
import com.sskj.base.api.Constant;
import com.sskj.base.base.HttpData;
import com.sskj.base.bean.HomeCommonBean;
import com.sskj.base.bean.rxbus.MainChangeTabBean;
import com.sskj.base.rxbus2.RxBus;


/**
 * @author Hey
 * Create at  2019/04/10
 */
class SellGamPresenter extends BasePresenter<SellGamActivity> {

    public void getHomeDate() {
        httpService.getHomeDate()
                .tag(this)
                .execute(new JsonCallBack<HttpData<HomeCommonBean>>() {
                    @Override
                    public void onStart(Request<HttpData<HomeCommonBean>, ? extends Request> request) {
                        super.onStart(request);
                        mView.showLoading();
                    }

                    @Override
                    public void onSuccess(Response<HttpData<HomeCommonBean>> response) {
                        HttpData<HomeCommonBean> body = response.body();
                        if (body.getStatus() == Constant.OK) {
                            mView.getHomeDateSuccess(body.getData());
                        }

                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }


    public void sellGam(int money_id, String price, String payment, String secpwd) {
        httpService.sellGam(money_id, price, payment, secpwd)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtils.show(body.getMsg());
                        if (body.getStatus() == Constant.OK) {
                            mView.finish();
                            RxBus.getDefault().post(new MainChangeTabBean(1,Constant.SELL));
                        }
                    }

                    @Override
                    public void onStart(Request<HttpData, ? extends Request> request) {
                        super.onStart(request);
                        mView.showLoading();
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }
}
